<template>
    <div class="userCenter">
        <div class="breadcrumb-box">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>个人中心</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="center container td-f">
            <left-nav-bar :active="active"></left-nav-bar>
            <div class="right">
                <div class="line-ti">
                    <div>支付金额</div>
                </div>
                <div class="border">
                    <div class="border-l">月结金额</div>
                    <div class="border-r">￥{{money}}</div>
                </div>
                <div class="pay-choose" :class="index == 0?'select':''" @click="choose(0)">
                    <img class="icon" src="../../assets/pay/icon_pay_weixin.png" alt="">
                    <div class="pay-text">微信支付</div>
                    <div class="radio " :class="index == 0?'select':''"></div>
                </div>
                <div class="pay-choose" :class="index == 1?'select':''" @click="choose(1)">
                    <img class="icon" src="../../assets/pay/yue.png" alt="">
                    <div class="pay-text">月结支付</div>
                    <div class="radio" :class="index == 1?'select':''"></div>
                </div>
                <div class="company-info" v-if="index == 1">
                    <div class="info red">公司名称：{{transferInfo.transfer_company}}</div>
                    <div class="info">税号：{{transferInfo.transfer_tax}} </div>
                    <div class="info">单位地址：{{transferInfo.transfer_address}} </div>
                    <div class="info">电话号码：{{transferInfo.transfer_phone}}</div>
                    <div class="info">开户银行：{{transferInfo.transfer_bank}}</div>
                    <div class="info">银行账户：{{transferInfo.transfer_number}}</div>
                </div>
                <div class="border1" v-if="index == 1">
                    <div class="title">填写支付金额</div>
                    <div class="input">
                        <div class="">￥</div>
                        <input type="text" v-model="amount">
                    </div>
                    <div class="title">上传凭证</div>
                    <div style="height:20px"></div>
                    <el-upload :action="url" list-type="picture-card" :data="qiniuData" :limit="9" :on-success="handleAvatarSuccess_one" :multiple="false" name="files[]">
                        <i class="el-icon-plus"></i>
                    </el-upload>
                    <el-dialog :visible.sync="dialogVisible">
                        <img width="100%" :src="item" alt="" v-for="(item,index) in dialogImageUrl" :key="index">
                    </el-dialog>
                </div>
                <div style="height:20px"></div>
                <div class="pay-qrcode" ref="payQrcode"></div>
                <div class="submit" @click="confirm" v-if="showConfirm">确认支付</div>
            </div>
        </div>
        <div style="height: 200px"></div>
    </div>
</template>

<script>
import leftNavBar from "@components/leftNavBar";
import {
    getUser,
    getMyMessage,
    getMonthSelf,
    getOrderId,
    payMonth,
    payOrder,
} from "@api/user";
import { orderPayState } from "@api/order";
import { qiniuToken,transforPay } from "@api/public";
import QRCode from "qrcodejs2";
export default {
    name: "userCenter",
    data() {
        return {
            loading: false,
            money: "",
            amount: "",
            active: 1,
            url: "http://gongchangguanjia.3todo.com/api/article/upload",
            qiniuDomail: "",
            qiniuData: {},
            index: 1,
            userInfo: {},
            transferInfo:{},
            order_id: "",
            messageList: [],
            quotaInfo: "",
            showConfirm: true,
            orderStatusNum: {},
            dialogImageUrl: [],
            dialogVisible: false,
            timer: "",
        };
    },
    components: {
        leftNavBar,
    },
    methods: {
        // 变更支付方式
        choose(index) {
            this.index = index;
            if (index == 1) {
                this.$refs["payQrcode"].innerHTML = "";
                this.showConfirm = true;
            }
        },
        // 生成二维码
        creatQrCode(text, dom, w = 100, h = 100) {
            this.qrcode = new QRCode(dom, {
                text: text, // 需要转换为二维码的内容
                width: w,
                height: h,
                colorDark: "#000000",
                colorLight: "#ffffff",
                correctLevel: QRCode.CorrectLevel.H,
            });
        },
        // 获取月结金额
        getMoney() {
            getMonthSelf()
                .then((res) => {
                    console.log(res);
                    this.money = res.data.price;
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        // 检测支付是否成功
        heartBeat() {
            this.timer && clearInterval(this.timer);
            this.timer = setInterval(() => {
                this.time++;
                this.getOrderPayState();
            }, 3000);
        },
        // 支付成功就调用
        getOrderPayState() {
            orderPayState(this.order_id).then((res) => {
                if (res.data.paid == 1) {
                    this.timer && clearInterval(this.timer);
                    this.$dialog.toast({ mes: "支付成功" });
                    setTimeout(() => {
                        this.$router.go(-1);
                    }, 1000);
                }
            });
        },
        // 确认支付
        confirm() {
            if (this.money == 0 || this.money == "0.00") {
                this.$dialog.error("月结金额为0");
                return;
            }
            this.$refs["payQrcode"].innerHTML = "";
            if (this.index == 0) {
                console.log("微信支付");
                let data = {
                    uni: this.order_id,
                    paytype: "month",
                    from: "frompc",
                    price: this.money,
                };
                payOrder(data)
                    .then((res) => {
                        if (res.status == 200) {
                            console.log(res.data);

                            this.creatQrCode(
                                res.data.result.jsConfig,
                                this.$refs["payQrcode"],
                                100,
                                100
                            );
                            this.showConfirm = false;
                            this.heartBeat();
                            return;
                        }
                        this.$dialog.error(res.msg || "订单支付错误");
                    })
                    .catch((err) => {
                        console.log(err);
                    });
            }
            if (this.index == 1) {
                let amount = this.amount;
                let pay_image = "";
                if (this.dialogImageUrl.length != 0) {
                    pay_image = this.dialogImageUrl.join(",");
                } else {
                    return this.$dialog.error("请上传支付凭证");
                }
                let data = {
                    amount: amount,
                    pay_image: pay_image,
                };
                if (this.$route.query.id) {
                    data.id = this.$route.query.id;
                }
                payMonth(data)
                    .then((res) => {
                        if (res.status == 200) {
                            this.$dialog.toast({ mes: "凭证提交成功" });
                            setTimeout(() => {
                                this.$router.go(-1);
                            }, 1500);

                            return;
                        }
                        return this.$dialog.error(res.msg);
                    })
                    .then((err) => {
                        console.log(err);
                    });
            }
        },
        User() {
            let that = this;
            getUser().then((res) => {
                that.userInfo = res.data;

                that.orderStatusNum = res.data.orderStatusNum;
            });
        },

        // 获取订单号
        getId() {
            getOrderId({ type: 1 })
                .then((res) => {
                    console.log(res);
                    this.order_id = res.data.order_id;
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        handleAvatarSuccess_one(res, file, fileList) {
            if (res.data.length) {
                this.dialogImageUrl = this.dialogImageUrl.concat(
                    res.data[0].src
                );
            }
        },
        // upload img
        getQiniuToken() {
            qiniuToken()
                .then((res) => {
                    this.qiniuData.token = res.data.uptoken;
                    this.qiniuDomail = res.data.pc_domain + "/";
                })
                .catch((err) => {
                    this.$dialog.error(err.msg || "获取七牛数据失败");
                });
        },
        getTransfronPay(){
            transforPay().then(res=>{
                console.log(res)
                this.transferInfo = res.data;

            }).catch(err=>{
                console.log(err)
            })
        }
    },
    mounted() {
        this.User();
        this.getMoney();
        this.getQiniuToken();
        this.getId();
        this.getTransfronPay()
    },
};
</script>
<style >
.el-upload--picture-card {
    width: 88px;
    height: 88px;
    line-height: 88px;
}
.el-upload-list--picture-card .el-upload-list__item {
    width: 88px;
    height: 88px;
}
</style>
<style scoped  rel="stylesheet/scss" lang="scss" scoped>
$color: #da213d;
.userCenter {
    width: 100%;
    height: 100%;

    .center {
        /*width: 70%;*/
        margin: 0 auto;
        display: flex;

        .right {
            width: 1000px;
            margin-left: 32px;
            /*margin-top: 90px;*/
            .border1 {
                padding: 30px 20px;
                box-sizing: border-box;
                border: 1px solid #eaa090;
                border-radius: 5px;
                width: 640px;
                margin-top: 20px;
                .title {
                    font-size: 18px;
                    line-height: 18px;
                }
                .input {
                    margin-top: 10px;
                    margin-bottom: 20px;
                    width: 310px;
                    border-bottom: 1px solid #cccccc;
                    display: flex;
                    align-items: center;
                    input {
                        width: 100%;
                        height: 50px;
                        border: 0;
                        font-size: 24px;
                        &:focus {
                            outline: 0;
                        }
                    }
                    div {
                        font-size: 24px;
                        font-weight: bold;
                    }
                }
            }
            .submit {
                margin-top: 30px;
                width: 230px;
                height: 50px;
                background: #da213d;
                border-radius: 5px;
                font-size: 18px;
                font-weight: bold;
                text-align: center;
                color: #ffffff;
                line-height: 50px;
                cursor: pointer;
            }
            .border {
                width: 640px;
                margin-top: 20px;
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 15px 17px;
                box-sizing: border-box;
                border: 1px solid #eaa090;
                border-radius: 5px;
                .border-l {
                    font-size: 18px;
                    font-weight: bold;
                    color: #333333;
                }
                .border-r {
                    font-size: 18px;
                    font-weight: bold;
                    color: #333333;
                }
            }
            .company-info {
                background: #fcf8f8;
                padding: 30px 20px 10px;
                box-sizing: border-box;
                margin-top: 20px;
                .info {
                    margin-bottom: 30px;
                    font-size: 16px;
                    color: #333333;
                }
                .info.red {
                    color: #da213d;
                }
            }
            .pay-choose {
                width: 640px;
                height: 50px;
                border: 1px solid #eaa090;
                border-radius: 5px;
                display: flex;
                margin-top: 15px;
                align-items: center;
                padding: 0 20px;
                box-sizing: border-box;
                .icon {
                    width: 28px;
                    height: 28px;
                }
                .pay-text {
                    font-size: 16px;
                    color: #333333;
                    margin-left: 10px;
                    flex: 1;
                }
                .radio {
                    width: 16px;
                    height: 16px;
                    border: 1px solid #da213d;
                    border-radius: 100%;
                }
                .radio.select {
                    position: relative;
                    &::before {
                        content: "";
                        position: absolute;
                        top: 0;
                        bottom: 0;

                        border-radius: 100%;
                        left: 0;
                        right: 0;
                        margin: auto;
                        width: 8px;
                        height: 8px;
                        background: #da213d;
                    }
                }
            }
            .pay-choose.select {
                background: #fbf7f7;
            }
            .ti-top {
                border: 1px solid #efc2c1;
                border-top-left-radius: 5px;
                border-top-right-radius: 5px;
                .right-top {
                    display: flex;
                    height: 160px;
                    align-items: center;
                    background: url("../../assets/second_icon/center_bg.png")
                        no-repeat;
                    background-size: 100% 100%;
                    position: relative;

                    .left-ava {
                        margin-left: 55px;
                        width: 82px;
                        height: 82px;
                        border-radius: 50%;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        background-color: #fff;
                        box-shadow: inset 0 0 5px 1px
                            rgba($color: #000000, $alpha: 0.2);
                        img {
                            width: 74px;
                            height: 74px;
                            border-radius: 50%;
                        }
                    }
                    .detaiult-avatar {
                        margin-left: 55px;
                        width: 99px;
                        height: 99px;
                        border-radius: 50%;
                        background-color: #fff;
                        box-shadow: inset 0 0 5px 1px
                            rgba($color: #000000, $alpha: 0.2);
                        img {
                            width: 66px;
                            height: 66px;
                            margin-left: 10px;
                        }
                    }

                    .right-txt {
                        display: flex;
                        height: 99px;
                        justify-content: center;
                        align-items: center;
                        margin-left: 5px;

                        > div:nth-of-type(1) {
                            color: #ffffff;
                            font-size: 20px;
                            margin-left: 20px;
                            text-align: justify;
                        }

                        > div:nth-of-type(2) {
                            height: 32px;
                            line-height: 32px;
                            padding: 0 20px;
                            text-align: center;
                            margin-left: 20px;
                            background: linear-gradient(
                                270deg,
                                rgba(23, 22, 20, 0.3) 1%,
                                rgba(99, 77, 77, 0.3)
                            );
                            border-radius: 15px;
                            color: rgba(255, 255, 255, 1);
                            font-size: 18px;
                            // margin-top: 19px;
                            small {
                                padding-right: 2px;
                            }
                        }
                    }

                    .set-btn {
                        position: absolute;
                        right: 30px;
                        top: 50%;
                        width: 70px;
                        height: 30px;
                        font-size: 16px;
                        color: #fff;
                        cursor: pointer;
                        border-radius: 8px;
                        border: 1px solid #da213d;
                        background: #da213d;
                        transform: translateY(-50%);
                        transition: all 0.3s;
                    }

                    .set-btn:hover {
                        background: #fff;
                        color: #da213d;
                    }
                }

                .right-list {
                    display: flex;
                    height: 130px;
                    width: 100%;
                    align-items: center;
                    justify-content: space-around;
                    // margin: 0 auto;
                    cursor: pointer;

                    .li {
                        display: flex;
                        flex-direction: column;
                        width: 33.3%;
                        justify-content: center;
                        align-items: center;
                        position: relative;
                        &::before {
                            position: absolute;
                            right: 0;
                            top: 0;
                            bottom: 0;
                            margin: auto 0;
                            content: "";
                            width: 2px;
                            height: 47px;
                            background: #ecdfdd;
                            border-radius: 1px;
                        }
                        > div:nth-of-type(1) {
                            min-width: 25px;
                            height: 25px;
                            line-height: 25px;
                            text-align: center;
                            background-color: $color;
                            color: #ffffff;
                            font-size: 15px;
                            position: absolute;
                            z-index: 2;
                            border-radius: 50%;
                            margin: -40px 0 0 30px;
                        }

                        img {
                            width: 50px;
                            height: 41px;
                            object-fit: contain;
                        }

                        div:nth-of-type(2) {
                            color: rgba(102, 102, 102, 1);
                            font-size: 17px;
                            font-family: MicrosoftYaHei;
                            margin-top: 13px;
                        }
                    }

                    .li:last-child {
                        img {
                            max-width: 54px;
                        }
                        &::before {
                            display: none;
                        }
                    }
                }
            }

            .line-ti {
                width: 100%;
                border-bottom: 3px solid #dbdbdb;
                height: 40px;
                > div {
                    color: #da213d;
                    font-size: 18px;
                    font-family: MicrosoftYaHei-Bold;
                    border-bottom: 3px solid $color;
                    width: 72px;
                    height: 40px;
                    font-weight: bold;
                    line-height: 36px;
                    padding-left: 5px;
                }
            }

            .shop-list {
                .shop-li {
                    padding-bottom: 10px;

                    .top {
                        display: flex;
                        align-content: center;
                        justify-content: space-between;
                        margin: 30px 0 16px 0;

                        .le {
                            display: flex;
                            height: 24px;
                            align-items: center;

                            img {
                                width: 18px;
                                height: 16px;
                            }

                            > div {
                                color: rgba(51, 51, 51, 1);
                                font-size: 17px;
                                font-family: MicrosoftYaHei;
                                padding-left: 12px;
                            }
                        }

                        .ri {
                            > div {
                                color: #999999;
                            }
                        }
                    }

                    .bot {
                        width: 100%;
                        height: 40px;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;

                        .l {
                            display: flex;
                            height: 80px;
                            align-items: center;
                            margin-left: 15px;

                            img {
                                width: 80px;
                                height: 80px;
                            }

                            > div {
                                color: #333333;
                                padding-left: 15px;
                                font-size: 16px;
                                font-weight: 500;
                                width: 500px;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                            }
                        }

                        .r {
                            width: 85px;
                            height: 30px;
                            line-height: 30px;
                            text-align: center;
                            background: $color;
                            color: #3d75af;
                            font-size: 14px;
                            margin-right: 15px;
                            border-radius: 2px;
                            cursor: pointer;
                        }
                    }
                }

                .shop-li:not(:last-child) {
                    border-bottom: 1px solid #dbdbdb;
                }
            }
        }
    }
}
</style>
